﻿// See https://aka.ms/new-console-template for more information
class Calculate
{
   
    int[] createArray(int n)
    {
        int[] arr = new int[n];
        Console.WriteLine("请连续输入n个数，以空格隔开");
        string s = Console.ReadLine();
        //Console.WriteLine(s);
        string[] sArray = s.Split(' ');
        for (int i = 0; i < sArray.Length; i++)
        {
            //Console.WriteLine(sArray[i]);
            arr[i] = int.Parse(sArray[i]);
        }
            Console.WriteLine("数组创建完成");
        return arr;
    }
        //数组最大值
        int countMax(int[] arr)
        {
        int result = arr[0];
        for (int i = 0; i < arr.Length; i++)
            {
                
                if (arr[i] > result)
                {
                    result = arr[i];
                }
            }
            return result;
        }
        //数组最小值
        int countMin(int[] arr)
        {
        int result = arr[0];
        for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] < result)
                {
                    result = arr[i];
                }
            }
            return result;
        }
        //数组平均值
        double average(int[] arr)
        {
        double result = arr[0];
        for (int i = 0; i < arr.Length; i++)
            {
                result = result+arr[i];
            }
        result = result / arr.Length;
        return result;
        }
        //数组所有元素之和
        int count(int[] arr)
        {
        int result = arr[0];
        for (int i = 0; i < arr.Length; i++)
            {
                result = result+arr[i];
            }
            return (int)result;
        }
        //测试
        static void Main(string[] args)
        {
            Calculate c = new Calculate();
            Console.WriteLine("请输入数组长度");
            string s = Console.ReadLine();
        int n= int.Parse(s);
        Console.WriteLine(n);

            int[] arr = c.createArray(n);
        //int[] arr = new int[] { 11, 12, 41, 8 };

        Console.WriteLine("数组最大值为：");
            Console.WriteLine(c.countMax(arr));
            Console.WriteLine("数组最小值为：");
            Console.WriteLine(c.countMin(arr));
            Console.WriteLine("数组平均值为：");
            Console.WriteLine(c.average(arr));
            Console.WriteLine("数组所有元素和为：");
            Console.WriteLine(c.count(arr));
        }
    }
